<?php
class video_premium extends Model
{
    public static function getTableName()
    {
        return 'video_premium';
    }

    public function getPrimaryKey()
    {
        return array('video_id');
    }

    public function set($obj)
    {
        $this->video_id = $obj->id ? $obj->id : ''; 
        $this->ppv_flag = !empty($obj->premium_items) && in_array('ppv',$obj->premium_items) ? 1 : 0;
        $this->subscription_flag = !empty($obj->premium_items) &&  in_array('subscription',$obj->premium_items) ? 1  : 0; 
    }

    public function update($obj)
    {
        return Model::$dbo['w']->save($obj);
    }

    public function delete($id)
    {
        return Model::$dbo['w']->delete('video_premium','video_id=?',array($id));
    }

	/*
	 * by donald
	 */
	public function add_change_log($programme_id)
	{
		$field['type'] = $this->getTableName();
		$field['keys'] = array('video_id' => $this->video_id);
		$field['is_active'] = 1;
		$field['programme_id'] = $programme_id;
		$field['episode_id'] = 0;
		$field['is_publish'] = 0;

		change_log::updateOne($field);
	}

	/*
	 * by donald
	 * at 2011-10-07
	 */
	public function delete_change_log()
	{
		$type = $this->getTableName();
		$keys = array('video_id' => $this->video_id);
		$is_publish = 0;

		change_log::delTypeAndKeysLog($type, $keys, $is_publish);
	}


	/*
	 * by donald
	 * at 2011-10-07
	 */
	public static function getAll($video_id)
	{
		$ret = self::$dbo['w']->find(__CLASS__, 'video_id = ?', array($video_id));
		return !empty($ret) ? $ret[0] : array();
	}
}
?>
